package com.lkk.cg.domain;


import java.util.HashSet;
import java.util.Set;

public class Privilege {
    private Long id;
    private String name;
    private String url;
    private int type;
    Privilege parent;
    Set<Privilege> children = new HashSet<Privilege>();

    public Privilege(String name, String url, int type) {
        this.name = name;
        this.url = url;
        this.type = type;
    }

    public Privilege() {

    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getType() {
        return type;
    }

    /**
     * 设置权限类型
     *
     * @param type 权限的类型<br>1 代表需要授权 <br>2 代表登陆就可以访问
     */
    public void setType(int type) {
        this.type = type;
    }

    public Privilege getParent() {
        return parent;
    }

    public void setParent(Privilege parent) {
        this.parent = parent;
    }

    public Set<Privilege> getChildren() {
        return children;
    }

    public void setChildren(Set<Privilege> children) {
        this.children = children;
    }

    public void addChild(Privilege privilege) {
        this.children.add(privilege);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Privilege)) return false;

        Privilege privilege = (Privilege) o;

        if (type != privilege.type) return false;
        if (name != null ? !name.equals(privilege.name) : privilege.name != null) return false;
        if (url != null ? !url.equals(privilege.url) : privilege.url != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (url != null ? url.hashCode() : 0);
        result = 31 * result + type;
        return result;
    }
}
